package rs.etf.mips.crossroad.logic;

/**
 * Class for representing vehicle in the simulation logic.
 * @author Momcilo
 *
 */
public class Vehicle{

	private double x;
	private double y;
	private double dx;
	private double dy;
	private ITrafficSpace space;
	
    /**
     * Create new vehicle.
     */
    public Vehicle() {
		super();
		this.x = this.y = this.dx = this.dy = 0;
		this.space = null;
	}

    /**
     * Create new vehicle using specified parameters.
     * @param x the x-coordinate.
	 * @param y the y-coordinate.
	 * @param dx the v<sub>x</sub> value.
	 * @param dy the v<sub>y</sub> value.
	 * @param trafficSpace the traffic space the vehicle is moving in.
     */
    public Vehicle(double x, double y, double dx, double dy, ITrafficSpace space) {
		super();
		this.setParameters(x, y, dx, dy, space);
	}

	/**
	 * @param x the x-coordinate.
	 * @param y the y-coordinate.
	 * @param dx the v<sub>x</sub> value.
	 * @param dy the v<sub>y</sub> value.
	 * @param trafficSpace the traffic space the vehicle is moving in.
	 */
	public void setParameters(double x, double y, double dx, double dy, ITrafficSpace trafficSpace){
    	this.setX(x);
    	this.setY(y);
    	this.setDx(dx);
    	this.setDy(dy);
    	this.setSpace(trafficSpace);
    }
	
	/**
     * @return The traffic space the vehicle is moving in.
     */
    public ITrafficSpace getSpace() {
		return space;
	}

	/**
	 * Sets the traffic space the vehicle is moving in.
	 * @param space - the new traffic space the vehicle is moving in.
	 */
	public void setSpace(ITrafficSpace space) {
		this.space = space;
	}

	/**
	 * Set the new x-coordinate position of the vehicle relative to the beginning of the traffic space the vehicle is moving in.
	 * @param x the new x-coordinate. 
	 */
	void setX(double x) {
		this.x = x;
	}

	/**
	 * Set the new y-coordinate position of the vehicle relative to the beginning of the traffic space the vehicle is moving in.
	 * @param y the new y-coordinate. 
	 */
	void setY(double y) {
		this.y = y;
	}

	/**
     * @return The x coordinate relative to the beginning of the traffic space the vehicle is moving in. 
     */
    public double getX() {
        return x;
    }

    /**
     * @return The y coordinate relative to the beginning of the traffic space the vehicle is moving in.
     */
    public double getY() {
        return y;
    }
    
	/**
	 * Gets the velocity of the vehicle along x-coordinate relative to the beginning of the traffic space the vehicle is moving in.
	 * @return v<sub>x</sub> 
	 */
	public double getDx() {
		return dx;
	}
	
	/**
	 * Sets new velocity along the x-coordinate relative to the beginning of the traffic space the vehicle is moving in.
	 * @param dx - new value for v<sub>x</sub>
	 */
	public void setDx(double dx) {
		this.dx = dx;
	}
	
	/**
	 * Gets the velocity of the vehicle along y-coordinate relative to the beginning of the traffic space the vehicle is moving in.
	 * @return v<sub>y</sub> 
	 */
	public double getDy() {
		return dy;
	}

	/**
	 * Sets new velocity along the y-coordinate relative to the beginning of the traffic space the vehicle is moving in.
	 * @param dy - new value for v<sub>y</sub>
	 */
	public void setDy(double dy) {
		this.dy = dy;
	}

	/**
	 * Moves the vehicle.
	 * @return <b>true</b> if the vehicle is moved; otherwise, <b>false</b>.
	 */
	public boolean move(){
		return (space != null) && (space.move(this));
	}

	@Override
	public String toString() {
		return "Vehicle [x=" + x + ", y=" + y + ", dx=" + dx + ", dy=" + dy
				+ "]";
	}
		
}
